package cn.edu.lsu.integratedsurvey.bean.dto;

import cn.edu.lsu.integratedsurvey.bean.Student;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;

/**
 * 学生注册请求DTO对象
 * <p>如果涉及后期推广，应该还需要加入学院字段</p>
 *
 * @author Jasmine-drs
 * @date 2024/5/3 13:11
 */

@Data
public class StudentRegisterDto {

	@NotBlank(message = "[姓名]不能为空")
	@Size(max = 20, message = "编码长度不能超过20")
	@ApiModelProperty("姓名")
	private String name;

	@NotBlank(message = "[学号]不能为空")
	@Size(max = 11, message = "编码长度不能超过11")
	@ApiModelProperty("学号")
	private String studentNumber;

	@NotBlank(message = "[班级]不能为空")
	@Size(max = 255, message = "编码长度不能超过255")
	@ApiModelProperty("班级")
	private String grade;

	@NotBlank(message = "[专业]不能为空")
	@Size(max = 255, message = "编码长度不能超过255")
	@ApiModelProperty("专业")
	private String profession;

//	判空方法
	public boolean isEmpty() {
		return name.isBlank() || studentNumber.isBlank() || grade.isBlank() || profession.isBlank();
	}

	public Student convertToStudent(Integer operatorId) {
		Student student = new Student();
		student.setName(name);
		student.setStudentNumber(studentNumber);
		student.setGrade(grade);
		student.setProfession(profession);
		student.setOperatorId(operatorId);
//		设置时间
		student.setCreateTime(LocalDateTime.now());
		student.setUpdateTime(LocalDateTime.now());
		return student;
	}
}
